using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Brutal_Dare_Portable
{
    public class Passing : Microsoft.Xna.Framework.DrawableGameComponent
    {
        SpriteBatch spriteBatch;

        string firstLine = "Pass the Phone around!";

        int minTimeToPass = 4000, maxTimeToPass = 8000, currentTime = 0, timeToPass = 0;

        public Passing(Game game)
            : base(game)
        {
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            timeToPass = ((Game1)Game).rand.Next(minTimeToPass, maxTimeToPass);
            
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.PaleGoldenrod);

            spriteBatch.Begin();

            spriteBatch.DrawString(((Game1)Game).logoFont, ((Game1)Game).logoText,
                new Vector2((int)((GraphicsDevice.Viewport.TitleSafeArea.Width / 2) - (((Game1)Game).logoFont.MeasureString(((Game1)Game).logoText).X / 2)), 5), Color.Black);

            spriteBatch.DrawString(((Game1)Game).subTextFont, firstLine,
                    new Vector2((int)((GraphicsDevice.Viewport.TitleSafeArea.Width / 2) - (((Game1)Game).subTextFont.MeasureString(firstLine).X / 2)),
                                (int)((GraphicsDevice.Viewport.TitleSafeArea.Height / 2) - (((Game1)Game).subTextFont.MeasureString(firstLine).Y / 2))), Color.Black);

            spriteBatch.End();

            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            if (currentTime < timeToPass)
            {
                currentTime += gameTime.ElapsedGameTime.Milliseconds;
            }
            else
            {
                currentTime = 0;
                timeToPass = ((Game1)Game).rand.Next(minTimeToPass, maxTimeToPass);
                ((Game1)Game).ChangeGameState(Game1.GameState.Choose);
            }

            base.Update(gameTime);
        }
    }
}
